home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news3.noc.netcom.net!zdc!zippo!usenet
- From: Jim McFarland <jgm6@orkand.em.cdc.gov>
- Subject: Re: extern and static are they compatable
- Content-Type: text/plain; charset=us-ascii
- Sender: usenet@news.zippo.com
- Content-Transfer-Encoding: 7bit
- Nntp-Posting-Host: 158.111.166.77
- Organization: The Orkand Corporation
- Message-ID: <DKprxq.GFG@news.zippo.com>
- References: <4cedhf$g6i@cnn.cc.biu.ac.il> <ahicksDKM8Ap.FBp@netcom.com> <4ci3ao$f84@news.gate.net>
- X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
- Mime-Version: 1.0
- Date: Fri, 5 Jan 1996 15:20:05 GMT
-
- bhutto@gate.net (William Hutto) wrote:
- >In article <ahicksDKM8Ap.FBp@netcom.com>,
- > ahicks@netcom.com (Aaron Hicks at Netcom) wrote:
- >>Folks,
- >>
- >> I'm working on a project which requires use to create large array
- >>( approximately 500 K bytes ) so we decided to make it static so it would
- >>not have be created each time the routines that use it are called.
-
- The "static" keyword actually has two different uses, which you seem to be confusing
- here. When used in global scope, static does as those who previously replied to you post
- have noted... it limits the scope of the variable to the source file it is declared in.
- When static is used in an automatic variable declaration (i.e. within a function) then
- you get the behavior you describe, i.e. the variable is initialized once and retains its
- value between calls to the function. However to do what you actually describe, i.e.
- create a global variable for use by several functions, static is not needed unless you
- want to limit the scope of the variable to that one source file. Since you later needed
- to access the variable from another source file, as others have pointed out, static
- cannot be used. Does that help clear things up any?
-
- >>We then
- >>found out that we needed a nother program to acess this array so in the
- >second
- >>file we defined this array as a extern. Now each time we compile and link
- >>the programs we get an error stating that the array is undefined. The error
- >>is displayed while linking. After reading all I could find about extern
- >>I can not find any thing that says this is correct behavior. I then changed
- >>the static decloration to a non static and the thing compiles with out a
- >>problem. Now I'm wandering if any of the great mind on the net could
- >>enlighten me as to why the static declaration would cause this error.
- >
-
-
-